<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.44">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #ad140d}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
span.s1 {color: #001bb9}
span.s2 {color: #606060}
span.s3 {color: #000000}
span.s4 {color: #2c7014}
span.s5 {color: #ad140d}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1">//SLUGens released under the GNU GPL as extensions for SuperCollider 3, by Nick Collins, http://www.informatics.sussex.ac.uk/users/nc81/</p>
<p class="p2"><br></p>
<p class="p3"><b>SortBuf<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>Karplus-Strong via a sorting algorithm</b></p>
<p class="p2"><br></p>
<p class="p4"><b>SortBuf.ar(bufnum, sortrate, reset)</b></p>
<p class="p5"><br></p>
<p class="p4">In this UGen a target buffer gets sorted into increasing sample values over time- the sorting process causes gradual distortion. The sorting algorithm used is just a naive one of O(N^2) so effects are very dependent on sample length and sorting speed. It works best with small buffers and large sorting speeds will make it very CPU intensive. <span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">SortBuf assumes that the sample rate of the target buffer is the same as the soundcard output sample rate.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><b>bufnum</b>- target buffer, will be overwritten by the procedure.<span class="Apple-converted-space"> </span></p>
<p class="p4"><b>sortrate</b>- number of sorting iterations per play through of the buffer</p>
<p class="p4"><b>reset</b>- restart the sorting procedure.<span class="Apple-converted-space"> </span></p>
<p class="p5"><span class="Apple-converted-space"> </span></p>
<p class="p6"><br></p>
<p class="p7">b= <span class="s1">Buffer</span>.read(s,<span class="s2">"sounds/break"</span>,20000,10000);</p>
<p class="p6"><br></p>
<p class="p1">//gradual erosion</p>
<p class="p7">(</p>
<p class="p8"><span class="s1">SynthDef</span><span class="s3">(</span>"help-sortbuf"<span class="s3">,{</span><span class="s1">arg</span><span class="s3"> bufnum;</span></p>
<p class="p7"><span class="s1">Out</span>.ar(0,</p>
<p class="p7"><span class="s1">Pan2</span>.ar(<span class="Apple-converted-space"> </span></p>
<p class="p7"><span class="s1">SortBuf</span>.ar(bufnum,<span class="s1">LFNoise0</span>.kr(5,50000,60000),0)</p>
<p class="p7">,0.0))</p>
<p class="p7">}).play(s,[<span class="s4">\bufnum</span>, b.bufnum]);</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p7">c= <span class="s1">Buffer</span>.read(s,<span class="s2">"sounds/break"</span>,20000,10000);</p>
<p class="p1"><span class="s3">c.copy(b); </span>//restore buffer</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p1">//short 2000 sample buffer sorted over about 10 seconds</p>
<p class="p7">b= <span class="s1">Buffer</span>.read(s,<span class="s2">"sounds/break"</span>,20000,2000);</p>
<p class="p7">{<span class="s1">SortBuf</span>.ar(b.bufnum,10000,1)}.play</p>
<p class="p6"><br></p>
<p class="p7">(</p>
<p class="p7">s = <span class="s1">Server</span>.local;</p>
<p class="p7">b = <span class="s1">Buffer</span>.alloc(s, 512, 1);</p>
<p class="p7">c = <span class="s1">Buffer</span>.alloc(s, 512, 1);</p>
<p class="p7">b.sine1(1.0/[1,2,3,4,5,6], <span class="s1">true</span>, <span class="s1">true</span>, <span class="s1">true</span>);</p>
<p class="p7">c.sine1(1.0/[1,2,3,4,5,6], <span class="s1">true</span>, <span class="s1">true</span>, <span class="s1">true</span>);</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p7">(</p>
<p class="p7"><span class="s1">SynthDef</span>(<span class="s2">"help-sortbuf2"</span>,{ <span class="s1">arg</span> out=0,bufnum=0;</p>
<p class="p6"><br></p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s1">SortBuf</span>.ar(b.bufnum,1000,1); <span class="s5">//attacking b over time</span></p>
<p class="p6"><br></p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="s1">Out</span>.ar(out,</p>
<p class="p1"><span class="s3"><span class="Apple-tab-span">	</span></span>//RLPF.ar(</p>
<p class="p7"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s1">Osc</span>.ar(b.bufnum, <span class="s1">MouseX</span>.kr(20,100), 0, 0.5)</p>
<p class="p1"><span class="s3"><span class="Apple-tab-span">	</span></span>//<span class="Apple-tab-span">	</span>, MouseY.kr(200,4000),0.1)</p>
<p class="p7"><span class="Apple-tab-span">	</span>)</p>
<p class="p7">}).play(s,[<span class="s4">\out</span>, 0]);</p>
<p class="p7">)</p>
<p class="p6"><br></p>
<p class="p1"><span class="s3">c.copyData(b); </span>//restore buffer</p>
<p class="p6"><br></p>
</body>
</html>
